home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Non arithmetic integer type.
- Date: Wed, 27 Mar 96 20:38:33 GMT
- Organization: none
- Message-ID: <827959113snz@genesis.demon.co.uk>
- References: <4igp11$83a@airdmhor.gen.nz> <4ihfjcINNss6@keats.ugrad.cs.ubc.ca> <4ijp6i$cdu@airdmhor.gen.nz>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ijp6i$cdu@airdmhor.gen.nz>
- gumboot@airdmhor.gen.nz "Simon Hosie" writes:
-
- >In article <4igp11$83a@airdmhor.gen.nz>,
- >Simon Hosie <gumboot@airdmhor.gen.nz> wrote:
- >> I've been trying to create a data type that holds an int or intlike chunk
- >> of data that is incompatible with any other types (to generate errors if
- >> someone assumes that it's the same type as an int).. I've found that
- >>
- >> typedef struct { int Value; } TypeA;
- >> typedef struct { int ValueWithADifferentName; } TypeB;
- >>
- >> makes two compatible types; a variable of TypeA can be assigned to a
- >> variable of TypeB without any warnings.. but
-
- According to ANSI C these 2 types are incompatible. That means that if you
- try to assign a variable of TypeA to a variable of typeB then a conforming
- compiler must generate a diagnostic. That's true even if the member names
- are the same (within a single translation unit).
-
- >Kazimir Kylheku:
- >> Your compiler has a gratuitous extension that allows for structural
- >> equivalence type checking.
- >
- >> In standard C, structures with a different tag name are different.
-
- Not, as far as I can tell, if they are in different translation units. Of
- course in that case the possibility of assignment between 2 such structures
- doesn't exist. However it would certainly be relevant to structures with
- external linkage.
-
- > Structures
- >> declard with _no tag_ are always incompatible with each other and with other
- >> structures that have tags.
- > So, do you reckon that if I gave then tags that were _different_ rather
- >than absent then they would have another chance at being recognised as
- >different? [Jumps to D*S shell..] Nope.. Let's try unions.. Nope.. .CPP
- >extention.. Got it.
- >
- > Is it a C rule or a C++ rule that they be incompatible?
-
- It is a C rule. Are you sure that you compiling using options that select
- a (claimed) full ANSI compliant mode?
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-